<?php
/**
 * 
 * 将数组转化为json字符串
 * @author Administrator
 *
 */
class Json
{
	static function arrayRecursive(&$array, $function, $apply_to_keys_also = false) 
	{
	    static $recursive_counter = 0;
	    if (++$recursive_counter > 1000) { 
	        die('possible deep recursion attack'); 
	    } 
	    foreach ($array as $key => $value) { 
	        if (is_array($value)) { 
	            self::arrayRecursive($array[$key], $function, $apply_to_keys_also); 
	        } else { 
	            $array[$key] = $function($value); 
	        } 
	 
	        if ($apply_to_keys_also && is_string($key)) { 
	            $new_key = $function($key); 
	            if ($new_key != $key) { 
	                $array[$new_key] = $array[$key]; 
	                unset($array[$key]); 
	            } 
	        } 
	    } 
	    $recursive_counter--; 
	} 
	
	/**
	 * 
	 * 将数组转化为json字符串
	 * @param array $array 
	 */
	public static function _toJSON($arr)
	{
		self::arrayRecursive($arr, 'urlencode', true); 
	    $json = json_encode($arr); 
	    return urldecode($json);
	}
	
	
	
	
}

?>